package com.lexian.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lexian.entity.Store;
import com.lexian.service.StoreService;
import com.lexian.utils.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 门店信息表 前端控制器
 * </p>
 *
 * @author testjava
f */
@RestController
@RequestMapping("/store")
public class StoreController {


    @Autowired
    private StoreService storeService;

    /**
     * 查询所有门店信息
     * @return
     */
    @GetMapping("getInfo")
    public CommonResponse getInfo(){
        List<Store> info = storeService.getInfo();
        return CommonResponse.ok().data("info",info);
    }

    /**
     * 添加门店信息
     * @param store 实体对象
     * @return
     */
    @PostMapping("addStore")
    public CommonResponse addStore(@RequestBody Store store){
         storeService.addStore(store);
         return CommonResponse.ok();
    }

    /**
     * 查询门店状态
     * @param storeId
     * @return
     */
    @GetMapping("getStoreIdBy")
    public CommonResponse getStoreIdBy(long storeId){
        QueryWrapper<Store> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",storeId);
        wrapper.eq("status",1);
        long storeId1 = storeService.getOne(wrapper).getStoreId();
        return CommonResponse.ok().data("storeId",storeId1);
    }
}

